package com.atguigu.practice;

import java.util.Scanner;

public class TheLeastStepsToFibonacci {
    public static void main(String[] args) {
        Scanner scanner=new Scanner(System.in);
        int n=scanner.nextInt();
        int m=n;
        int a=1,b=1;
        int c=1;
        int[] array=new int[1000000];
        array[1]=1;
        while(c<array.length){
            c=a+b;
            if(c<array.length) {
                array[c]++;
            }
            a=b;
            b=c;
        }
        int minLeft=0;
        while(n>0){
            if(array[n]!=0){
                break;
            }
            n--;
            minLeft++;
        }
        int minRight=0;
        while(m<array.length){
            if(array[m]!=0){
                break;
            }
            m++;
            minRight++;
        }
        System.out.println(minLeft<minRight?minLeft:minRight);
    }
}
